package com.dogdog.activity;

import com.dogdog.fragment.Hand_found;
import com.dogdog.fragment.Hand_message;
import com.dogdog.fragment.Hand_person;
import com.dogdog.fragment.Hand_square;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class Hand_main1 extends Activity implements OnCheckedChangeListener {

	private RadioGroup radioGroup;
	private LinearLayout frame;
	private Hand_found hand_found;
	private Hand_message hand_message;
	private Hand_square hand_square;
	private Hand_person hand_person;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.hand_main_bottom);
		initView();
		setDefaultFragment();
	}

	private void setDefaultFragment() {
		FragmentManager fm = getFragmentManager();
		FragmentTransaction transaction = fm.beginTransaction();
		Intent intent = getIntent();
		String tag = intent.getStringExtra("tag");
		hand_found=new Hand_found();
		transaction.replace(R.id.frame, hand_found);
		transaction.commit();
	}

	private void initView() {
		radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
		radioGroup.setOnCheckedChangeListener(this);
		frame = (LinearLayout) findViewById(R.id.frame);
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		FragmentManager fm = getFragmentManager();
		FragmentTransaction transaction = fm.beginTransaction();
		switch (checkedId) {
		case R.id.rb_found:
			if (hand_found == null) {
				hand_found = new Hand_found();
			}
			transaction.replace(R.id.frame, hand_found);

			break;
		case R.id.rb_message:
			if (hand_message == null) {
				hand_message = new Hand_message();
			}

			transaction.replace(R.id.frame, hand_message);
			break;
		case R.id.rb_square:
			if (hand_square == null) {
				hand_square = new Hand_square();
			}
			transaction.replace(R.id.frame, hand_square);
			break;
		case R.id.rb_person:
			if (hand_person == null) {
				hand_person = new Hand_person();
			}
			transaction.replace(R.id.frame, hand_person);
			break;
		}
		transaction.commit();
	}

}
